﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevTeam;

using System;
using System.Data;

namespace ConfExpert.Forms
{
    public partial class GenericReports : XForm
    {
        public GenericReports()
        {
            InitializeComponent();
        }

        private void R_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetR");
            gridView1.MakeColumnInvisible("SP", "FormName", "AddS", "F0", "F1", "FK", "AddS_2", "F0_2", "F1_2");
            gridView1.MakeReadOnly();
            gridView1.DoubleClick += gridView1_DoubleClick;
            gridView1.MakeRowSelectable();
            gridView1.BestFitColumns();
            this.Shown += R_Shown;
        }

        void R_Shown(object sender, EventArgs e)
        {
            gridView1.ShowFindPanel();
        }

        void gridView1_DoubleClick(object sender, EventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();
            if(dr!=null)
            {
                string SP = dr["SP"].ToStr();
                string Name = dr["Name"].ToStr();
                string FormName = dr["FormName"].ToStr();
                string AddS = dr["AddS"].ToStr();
                string F0 = dr["F0"].ToStr();
                string F1 = dr["F1"].ToStr();
                string FK = dr["FK"].ToStr();
                string AddS_2 = dr["AddS_2"].ToStr();
                string F0_2 = dr["F0_2"].ToStr();
                string F1_2 = dr["F1_2"].ToStr();

                Type[] aoArgTypes = new Type[9] {
                    Type.GetType("System.String"), 
                    Type.GetType("System.String"), 
                    Type.GetType("System.String"), 
                    Type.GetType("System.String"), 
                    Type.GetType("System.String"),
                    Type.GetType("System.String"), 
                    Type.GetType("System.String"), 
                    Type.GetType("System.String"), 
                    Type.GetType("System.String")
                };

                if (FormName != string.Empty)
                {
                    Type oType = Type.GetType(FormName);
                    AppSession.MainForm.ShowMdiChildForm(oType);
                }
                else
                    AppSession.MainForm.ShowMdiChildForm(typeof(Rx), Name, SP, AddS, F0, F1, FK, AddS_2, F0_2, F1_2);
                /*
                Type oType = Type.GetType("ConfExpert.Forms.Rx");
                ConstructorInfo oConstructorInfo = oType.GetConstructor(aoArgTypes);
                Object[] aoArgs = new Object[9] { Name, SP, AddS, F0, F1, FK, AddS_2, F0_2, F1_2 };
                Form oForm = (Form)oConstructorInfo.Invoke(aoArgs);
                oForm.Show();
                 * */
            }
        }
    }
}
